package com.cykj.user.service.impl;

import com.cykj.common.dto.ResponseDTO;
import com.cykj.common.entity.EducationBackgroundDO;
import com.cykj.common.entity.OnlineResumeDO;
import com.cykj.common.entity.ProjectHistoryDO;
import com.cykj.common.entity.WorkHistoryDO;
import com.cykj.user.mapper.OnlineResumeMapper;
import com.cykj.user.service.IOnlineResumeService;
import com.cykj.user.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.user.service.impl
 * @Author: 浮行
 * @CreateTime: 2025-08-21 10:38
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class OnlineResumeServiceImpl implements IOnlineResumeService {
    @Autowired
    private OnlineResumeMapper onlineResumeMapper;

    @Override
    public ResponseDTO insertWork(WorkHistoryVO workHistoryVO) {
        Integer res = onlineResumeMapper.insertWork(workHistoryVO);
        if(res > 0){
            return ResponseDTO.success(workHistoryVO.getWorkHistoryId());
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO insertProjectHistory(ProjectHistoryVO projectHistoryVO) {
        Integer res = onlineResumeMapper.insertProjectHistory(projectHistoryVO);
        if(res > 0){
            return ResponseDTO.success(projectHistoryVO.getProjectHistoryId());
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO insertEducationBackground(EducationBackgroundVO educationBackgroundVO) {
        Integer res = onlineResumeMapper.insertEducationBackground(educationBackgroundVO);
        if(res > 0){
            return ResponseDTO.success(educationBackgroundVO.getEducationBackgroundId());
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO deleteEducationBackground(Integer educationBackgroundId) {
        Integer res = onlineResumeMapper.deleteEducationBackground(educationBackgroundId);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO deleteProjectHistory(Integer projectHistoryId) {
        Integer res = onlineResumeMapper.deleteProjectHistory(projectHistoryId);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO deleteWorkHistory(Integer workHistoryId) {
        Integer res = onlineResumeMapper.deleteWorkHistory(workHistoryId);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO updateWorkHistory(List<WorkHistoryVO> workHistoryVO) {
        Integer res = onlineResumeMapper.updateWorkHistory(workHistoryVO);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO updateEducationBackground(List<EducationBackgroundVO> educationBackgroundVOS) {
        Integer res = onlineResumeMapper.updateEducationBackground(educationBackgroundVOS);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO updateProjectHistory(List<ProjectHistoryVO> projectHistoryVO) {
        Integer res = onlineResumeMapper.updateProjectHistory(projectHistoryVO);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO selectWorkHistory(WorkHistoryVO workHistoryVO) {
        List<WorkHistoryDO> workHistoryDOS = onlineResumeMapper.selectWorkHistory(workHistoryVO);
            if(workHistoryDOS != null){
                return ResponseDTO.success(workHistoryDOS);
            }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO selectProjectHistory(ProjectHistoryVO projectHistoryVO) {
        List<ProjectHistoryDO> projectHistoryDOS = onlineResumeMapper.selectProjectHistory(projectHistoryVO);
        if(projectHistoryDOS != null){
            return ResponseDTO.success(projectHistoryDOS);
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO selectEducationBackground(EducationBackgroundVO educationBackgroundVO) {
        List<EducationBackgroundDO> educationBackgroundDOS = onlineResumeMapper.selectEducationBackground(educationBackgroundVO);
        if(educationBackgroundDOS != null){
            return ResponseDTO.success(educationBackgroundDOS);
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO updateCertificates(OnlineResumeVO onlineResumeVO) {
        Integer res = onlineResumeMapper.updateCertificates(onlineResumeVO);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO selectUserAdvantageAndCertificate(OnlineResumeVO onlineResumeVO) {
        OnlineResumeDO onlineResumeDO = onlineResumeMapper.selectUserAdvantageAndCertificate(onlineResumeVO);
        if(onlineResumeDO != null){
            return ResponseDTO.success(onlineResumeDO);
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO updateAdvantage(OnlineResumeVO onlineResumeVO) {
        Integer res = onlineResumeMapper.updateAdvantage(onlineResumeVO);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }

    @Override
    public ResponseDTO updateJobStatus(UserVO userVO) {
        Integer res = onlineResumeMapper.updateJobStatus(userVO);
        if(res > 0){
            return ResponseDTO.success();
        }
        return ResponseDTO.error();
    }
}
